package com.example.demo;

import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.Arrays;
import java.util.List;

@RestController
public class RequestController {
    @RequestMapping("r1")
    public String r1(String[] array){
        return "接收数组参数"+ Arrays.toString(array);
    }

    @RequestMapping("r2")
    public String r2(@RequestParam List<String> list){
        return "接收list参数："+list;
    }

    //要利用json接收正文整个对象，就要加上注解@RequestBody
    @RequestMapping("r3")
    public String r3(@RequestBody Student student) {
        return "接收参数:"+student;
    }

    //从路径中获取参数
    @RequestMapping("/article/{articleId}")
    public String r4(@PathVariable("articleId") Integer articleId) {
        return "接收参数,articleId:"+articleId;
    }

    @RequestMapping("r5")
    //@RequestPart与@RequestParam用法基本相同，都是为了重命名。
    public String r5(@RequestPart("file") MultipartFile imgFile) {
        String originalFilename = imgFile.getOriginalFilename();
        return "接收参数,文件名称:"+originalFilename;
    }
}
